#!/bin/bash

#工作空间默认变量
WORKSPACE=/home/dragon/os
BIN_NAME=$0
#调试标志
DEBUG_FLAG="0"
# 运行类型（bochs/qemu）
RUN_TYPE=""
until [ -z "$1" ]  # Until all parameters used up
do
	if [ $1 == "-d" ];then
		shift
		if [ ! -z "$1" ];then
			WORKSPACE=$1
		fi
	fi
	if [ $1 == "--debug" ];then
		DEBUG_FLAG="1"
	fi
	if [ $1 == "--help" ];then
		printf "%s [commands] {%s|%s}\n\t-d workspace\n-t --debug debug mode\n\t--help show message\n" $BIN_NAME "qemu" "bochs"
		exit 0
	fi
	RUN_TYPE=$1
  shift
done
cd $WORKSPACE # 切换到工作目录
if [ "x$RUN_TYPE" == "xqemu" ];then
	if [ $DEBUG_FLAG == "1" ];then
		qemu-system-x86_64 -device piix3-ide,id=ide -drive id=disk,file=dev/hd.img,format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -device isa-vga -s -S
	else
		qemu-system-x86_64 -device piix3-ide,id=ide -drive id=disk,file=dev/hd.img,format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -device isa-vga
	fi
	
elif [ "x$RUN_TYPE" == "xbochs" ];then
	if [ $DEBUG_FLAG == "1" ];then
		bochsgdb -q -f bochs.disk_gdb
	else
		bochs -q -f bochs.disk_x11
	fi
else
	echo "Input run type"
	exit 0
fi
# gdb 调试
# qemu-system-x86_64 -device piix3-ide,id=ide -drive id=disk,file=dev/hd.img,format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -device isa-vga -s -S
# 直接启动
# qemu-system-x86_64 -device piix3-ide,id=ide -drive id=disk,file=dev/hd.img,format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -device isa-vga

# bochs 启动
# bochs -q -f bochs.disk_x11

